using System.Collections.Generic;
using Data;
using Model.Entities;
using Nethouse.Lib.Mvp;

namespace Business.EditOrderUC
{
    public class ShowOrderPresenter : Presenter<IShowOrderView>
    {
        private readonly IRepository<Order> orderRepository;

        public ShowOrderPresenter(IRepository<Order> orderRepository)
        {
            this.orderRepository = orderRepository;
        }

        protected override void ViewLoaded()
        {
            EventBus.Subscribe<OrderSelected>(OrderSelectedEvent);
        }

        private void OrderSelectedEvent(OrderSelected orderSelected)
        {
            if (orderSelected.OrderId > 0)
            {
                Order currentOrder = orderRepository.GetById(orderSelected.OrderId);

                View.OrderNumber = currentOrder.OrderNumber;
                View.OrderRowList = currentOrder.OrderRowList;
            }
            else
            {
                View.OrderNumber = string.Empty;
                View.OrderRowList = new List<OrderRow>();
            }
        }
     }
}
